package cn.liip.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import cn.liip.beans.Student;
import cn.liip.dao.IManageDao;
import cn.liip.dao.ManageDaoMySqlImpl;

public class ManageAction extends BaseAction implements SessionAware {

	Map<String, Object> session;
	private Student student;
	IManageDao manageDao = new ManageDaoMySqlImpl();
	// IManageDao manageDao = new ManageDaoMongoImpl();
	private List<Student> studentList;
	private String _id;

	// 取现有所有学生名单
	@SuppressWarnings("unchecked")
	public String list() {
		setStudentList(manageDao.getAllStudent());
		return "success";
	}

	// 添加
	public String add() {
		return "success";
	}

	// 修改
	public String edit() {
		setStudent(manageDao.findOne(_id));
		return "success";
	}

	// 添加保存
	public String addSave() {
		manageDao.add(student);
		return "edit_success";
	}

	// 修改保存
	public String editSave() {
		manageDao.update(student);
		return "edit_success";
	}

	// 添加保存
	public String del() {
		if (manageDao.del(_id) > 0) {
			return "edit_success";
		} else {
			return "error";
		}
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public List<Student> getStudentList() {
		return studentList;
	}

	public void setStudentList(List<Student> studentList) {
		this.studentList = studentList;
	}

	public String get_id() {
		return _id;
	}

	public void set_id(String _id) {
		this._id = _id;
	}

}